/*
 */

package com.railway.msg.dao.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;
import cn.org.rapid_framework.page.Page;
import com.railway.common.base.BaseIbatisDao;
import com.railway.common.base.IdGenerator;
import com.railway.msg.constants.IConstant;
import com.railway.msg.dao.IMsgReciveDao;
import com.railway.msg.model.MsgRecive;
import com.railway.msg.vo.query.MsgReciveQuery;

/**
 * @author  jiangcheng
 * @version 1.0
 * @since 1.0
 */

@Repository("msgReciveDao")
public class MsgReciveDaoImpl extends BaseIbatisDao<MsgRecive,java.lang.String> implements IMsgReciveDao{
	
	@Override
	public String getIbatisSqlMapNamespace() {
		return "MsgRecive";
	}
	
	public MsgRecive getById(java.lang.String id){
		return super.getById( id);
	}
	
	public void deleteById(java.lang.String id){
		super.deleteById(id);
	}
	
	/** 插入数据 */
	public void save(MsgRecive entity){
		if(StringUtils.isEmpty(entity.getId())) {
			entity.setId(IdGenerator.genUUIDStr());
		}
		super.save(entity);
	}
	
	/** 更新数据 */
	public void update(MsgRecive entity){
		super.update(entity);
	}

	public boolean isUnique(MsgRecive entity, String uniquePropertyNames){
		return super.isUnique( entity, uniquePropertyNames);
	}
	
	public List<MsgRecive> findAll(){
		return super.findAll();
	}
	
	public void saveOrUpdate(MsgRecive entity) {
		if(StringUtils.isEmpty(entity.getId())) {
			entity.setId(IdGenerator.genUUIDStr());
			super.save(entity);
		}
		else 
			super.update(entity);
	}	
	public Page findPage(MsgReciveQuery query) {		
		return pageQuery("MsgRecive.findPage",query);
	}
	public Page findPageEntity(MsgReciveQuery query) {		
		return pageQuery("MsgRecive.findPageEntity",query);
	}


	public long getMsgCountByUserID(String userid) {
		try{
		  Map map = new HashMap ();
		  map.put("userid", userid);
		  map.put("status", IConstant.MSG_STATUS_UNREAD);
		  Number result = (Number)getSqlMapClientTemplate().queryForObject("MsgRecive.findMsgCountByUserID", map);
		  if( result == null) return 0L ;
		  return  result.longValue();
		}catch(Exception e){
			e.printStackTrace();
		}
		return 0L;
	
	}



	
}
